from apps.clsbb.model.check_models import *
from apps.clsbb.model.log_models import *
from apps.common.models import ClsbbBaseModel, PbiBaseCheck
from extensions.models import *

class Clsbb_Common_Pdfs(Model):
    """七库全书通用pdf"""
    company = ForeignKey('system.Company', on_delete=CASCADE, blank=True, default=None,
                         related_name='clsbb_Common_Pdfs')
    file = FileField(upload_to='clsbb_common_pdf/',verbose_name='文件',help_text='文件')
    name = CharField(max_length=256, verbose_name='文件名称',help_text='文件名称')
    # type = IntegerField(verbose_name='文件类型')#1=方案库2=案例库3=投标库4=产品库5=合作伙伴库6=公司资质库7=人员资质库
    type = CharField(max_length=256, verbose_name='文件类型',help_text='文件类型')#1=方案库2=案例库3=投标库4=产品库5=合作伙伴库6=公司资质库7=人员资质库
    filled_by = ForeignKey('system.User', on_delete=SET_NULL,null=True, blank=True, default=None,
                           related_name='Clsbb_Common_Pdfs')  # 支填报人
    add_time = DateTimeField(auto_now_add=True, verbose_name='创建时间', null=True, blank=True)


# 方案库基础信息
class Clsbbfak_Records(ClsbbBaseModel):
    company = ForeignKey('system.Company', on_delete=CASCADE, blank=True, default=None, related_name='Clsbbfak_Records')
    describe = CharField(max_length=1024, verbose_name='方案描述', null=True, blank=True,help_text='方案描述')
    keywords = CharField(max_length=255, verbose_name='方案关键词', null=True, blank=True,help_text='方案关键词')
    classification = ForeignKey('system.Dict_item', on_delete=CASCADE,verbose_name='方案分类', blank=True, default=None, related_name='Clsbbfak_Records_dict_item_classification')
    industry = ForeignKey('system.Dict_item', on_delete=CASCADE,verbose_name='方案行业', blank=True, default=None,related_name='Clsbbfak_Records_dict_item_industry')
    contact_scheme = CharField(max_length=255, verbose_name='方案联系人', null=True, blank=True)
    contact_phone_scheme = CharField(max_length=255, verbose_name='方案联系人电话', null=True, blank=True)
    name_partne = CharField(max_length=255, verbose_name='合作方名称', null=True, blank=True)
    contact_partne = CharField(max_length=255, verbose_name='合作方联系人', null=True, blank=True)
    contact_phone_partne = CharField(max_length=255, verbose_name='合作方联系人电话', null=True, blank=True)
    maintainer_scheme = CharField(max_length=255, verbose_name='方案维护人', null=True, blank=True)
    maintainer_phone_scheme = CharField(max_length=255, verbose_name='方案维护人联系电话', null=True, blank=True)
    attachments_scheme = ForeignKey(Clsbb_Common_Pdfs, on_delete=SET_NULL, null=True, blank=True, default=None,related_name='Clsbbfak_Records_dispatch_pdf')  # 附件
    downloads_log = ManyToManyField(Downloads_log,  null=True, blank=True, related_name='Clsbbfak_Records_downloads_records')   # 下载记录
    views_log = ManyToManyField(Views_log, null=True, blank=True, related_name='Clsbbfak_Records_views_records') # 浏览记录
    check_records = ManyToManyField(ClsbbfakCheck, blank=True, null=True, related_name='Clsbbfak_Records',
                                    verbose_name='审核记录')  # 审核记录
    filled_by = ForeignKey('system.User', on_delete=SET_NULL, null=True, blank=True, default=None,
                           related_name='Clsbb_Records')  # 支填报人
    next_checker = ForeignKey('system.User', on_delete=SET_NULL, null=True, blank=True, default=None,
                              related_name='Clsbb_next_checker')  # 下一步审核或操作的人

    def __str__(self):
        return self.name




# 案例库基础信息
class Clsbbalk_Records(ClsbbBaseModel):
    company = ForeignKey('system.Company', on_delete=CASCADE, blank=True, default=None, related_name='Clsbbalk_Records')
    describe = CharField(max_length=1024, verbose_name='简介', null=True, blank=True,help_text='简介')
    keywords = CharField(max_length=255, verbose_name='关键词', null=True, blank=True,help_text='关键词')
    customer_name = CharField(max_length=255, verbose_name='客户名称', null=True, blank=True,help_text='客户名称')
    industry = ForeignKey('system.Dict_item', on_delete=CASCADE,verbose_name='行业', blank=True, default=None,related_name='Clsbbalk_Records_dict_item_industry')
    product = ForeignKey('system.Dict_item', on_delete=CASCADE, verbose_name='产品', blank=True, default=None,related_name='Clsbbalk_Records_dict_item_product')
    project_scale = FloatField(verbose_name='项目规模', null=True, blank=True, default=0)
    bidding_or_not = BooleanField(verbose_name='是否招投标', null=True, blank=True)
    signatory = CharField(max_length=255, verbose_name='签约主体', null=True, blank=True)
    bid_winning_amount = FloatField(verbose_name='中标金额', null=True, blank=True, default=0)
    contact = CharField(max_length=255, verbose_name='案例联系人', null=True, blank=True)
    contact_phone = CharField(max_length=255, verbose_name='案例联系人电话', null=True, blank=True)
    name_partne = CharField(max_length=255, verbose_name='合作方名称', null=True, blank=True)
    contact_partne = CharField(max_length=255, verbose_name='合作方联系人', null=True, blank=True)
    contact_phone_partne = CharField(max_length=255, verbose_name='合作方联系人电话', null=True, blank=True)
    maintainer = CharField(max_length=255, verbose_name='案例维护人', null=True, blank=True)
    maintainer_phone = CharField(max_length=255, verbose_name='案例维护人联系电话', null=True, blank=True)
    attachments_case = ForeignKey(Clsbb_Common_Pdfs, on_delete=SET_NULL, null=True, blank=True, default=None,related_name='Clsbbalk_Records_dispatch_pdf')  # 案例文档附件
    acceptance_report= ForeignKey(Clsbb_Common_Pdfs, on_delete=SET_NULL, null=True, blank=True, default=None,related_name='Clsbbalk_Records_acceptance_report')  # 验收报告type=21
    case_contract= ForeignKey(Clsbb_Common_Pdfs, on_delete=SET_NULL, null=True, blank=True, default=None,related_name='Clsbbalk_Records_case_contract')  # 案例合同type=22
    notification_announcement= ForeignKey(Clsbb_Common_Pdfs, on_delete=SET_NULL, null=True, blank=True, default=None,related_name='Clsbbalk_Records_notification_announcement')  # 中标通知书或中标公告type=23
    bidding_documents= ForeignKey(Clsbb_Common_Pdfs, on_delete=SET_NULL, null=True, blank=True, default=None,related_name='Clsbbalk_Records_bidding_documents')  # 招标文件type=24
    downloads_log = ManyToManyField(Alk_Downloads_log,  null=True, blank=True, related_name='Clsbbalk_Records_downloads_records')   # 下载记录
    views_log = ManyToManyField(Alk_Views_log, null=True, blank=True, related_name='Clsbbalk_Records_views_records') # 浏览记录
    check_records = ManyToManyField(ClsbbalkCheck, blank=True, null=True, related_name='Clsbbalk_Records',
                                    verbose_name='审核记录')  # 审核记录
    filled_by = ForeignKey('system.User', on_delete=SET_NULL, null=True, blank=True, default=None,
                           related_name='Clsbbalk_Records_filled_by')  # 支填报人
    next_checker = ForeignKey('system.User', on_delete=SET_NULL, null=True, blank=True, default=None,
                              related_name='Clsbbalk_Records_next_checker')  # 下一步审核或操作的人

    def __str__(self):
        return self.name


# 投标库基础信息
class Clsbbtbk_Records(ClsbbBaseModel):
    company = ForeignKey('system.Company', on_delete=CASCADE, blank=True, default=None, related_name='Clsbbtbk_Records')
    describe = CharField(max_length=1024, verbose_name='简介', null=True, blank=True,help_text='简介')
    keywords = CharField(max_length=255, verbose_name='关键词', null=True, blank=True,help_text='关键词')
    template_type = ForeignKey('system.Dict_item', on_delete=CASCADE,verbose_name='模板类型', blank=True, default=None,related_name='Clsbbtbk_Records_dict_item_template_type')
    industry = ForeignKey('system.Dict_item', on_delete=CASCADE,verbose_name='行业', blank=True, default=None,related_name='Clsbbtbk_Records_dict_item_industry')
    product = ForeignKey('system.Dict_item', on_delete=CASCADE, verbose_name='产品', blank=True, default=None,related_name='Clsbbtbk_Records_dict_item_product')
    contact = CharField(max_length=255, verbose_name='资料联系人', null=True, blank=True)
    contact_phone = CharField(max_length=255, verbose_name='资料联系人电话', null=True, blank=True)
    contact_email = CharField(max_length=255, verbose_name='资料联系人邮箱', null=True, blank=True)
    maintainer = CharField(max_length=255, verbose_name='资料维护人', null=True, blank=True)
    maintainer_phone = CharField(max_length=255, verbose_name='资料维护人联系电话', null=True, blank=True)
    maintainer_email = CharField(max_length=255, verbose_name='资料维护人邮箱', null=True, blank=True)
    attachments_data = ForeignKey(Clsbb_Common_Pdfs, on_delete=SET_NULL, null=True, blank=True, default=None,related_name='Clsbbtbk_Records_dispatch_pdf')  # 资料附件
    downloads_log = ManyToManyField(Tbk_Downloads_log,  null=True, blank=True, related_name='Clsbbtbk_Records_downloads_records')   # 下载记录
    views_log = ManyToManyField(Tbk_Views_log, null=True, blank=True, related_name='Clsbbtbk_Records_views_records') # 浏览记录
    check_records = ManyToManyField(ClsbbtbkCheck, blank=True, null=True, related_name='Clsbbtbk_Records',
                                    verbose_name='审核记录')  # 审核记录
    filled_by = ForeignKey('system.User', on_delete=SET_NULL, null=True, blank=True, default=None,
                           related_name='Clsbbtbk_Records_filled_by')  # 支填报人
    next_checker = ForeignKey('system.User', on_delete=SET_NULL, null=True, blank=True, default=None,
                              related_name='Clsbbtbk_Records_next_checker')  # 下一步审核或操作的人

    def __str__(self):
        return self.name
    

# 产品库基础信息
class Clsbbcpk_Records(ClsbbBaseModel):
    company = ForeignKey('system.Company', on_delete=CASCADE, blank=True, default=None, related_name='Clsbbcpk_Records')
    model = CharField(max_length=255, verbose_name='产品型号', null=True, blank=True,help_text='产品型号')
    functions = CharField(max_length=255, verbose_name='产品功能', null=True, blank=True,help_text='产品功能')
    cost_price = FloatField(verbose_name='产品成本价', null=True, blank=True, default=0)
    settlement_price = FloatField(verbose_name='产品结算价', null=True, blank=True, default=0)
    manufactor = CharField(max_length=255, verbose_name='厂家', null=True, blank=True, help_text='厂家')
    delete_flag = BooleanField(verbose_name='删除标识', null=True, blank=True)
    contact = CharField(max_length=255, verbose_name='产品联系人', null=True, blank=True)
    contact_phone = CharField(max_length=255, verbose_name='产品联系人电话', null=True, blank=True)
    maintainer = CharField(max_length=255, verbose_name='产品维护人', null=True, blank=True)
    maintainer_phone = CharField(max_length=255, verbose_name='产品维护人联系电话', null=True, blank=True)
    attachments_plan = ForeignKey(Clsbb_Common_Pdfs, on_delete=SET_NULL, null=True, blank=True, default=None,related_name='Clsbbcpk_Records_attachments_plan')  # 产品方案
    attachments_other = ForeignKey(Clsbb_Common_Pdfs, on_delete=SET_NULL, null=True, blank=True, default=None,related_name='Clsbbcpk_Records_attachments_other')  # 其它附件
    downloads_log = ManyToManyField(Cpk_Downloads_log,  null=True, blank=True, related_name='Clsbbcpk_Records_downloads_records')   # 下载记录
    views_log = ManyToManyField(Cpk_Views_log, null=True, blank=True, related_name='Clsbbcpk_Records_views_records') # 浏览记录
    check_records = ManyToManyField(ClsbbcpkCheck, blank=True, null=True, related_name='Clsbbcpk_Records',
                                    verbose_name='审核记录')  # 审核记录
    filled_by = ForeignKey('system.User', on_delete=SET_NULL, null=True, blank=True, default=None,
                           related_name='Clsbbcpk_Records_filled_by')  # 支填报人
    next_checker = ForeignKey('system.User', on_delete=SET_NULL, null=True, blank=True, default=None,
                              related_name='Clsbbcpk_Records_next_checker')  # 下一步审核或操作的人

    def __str__(self):
        return self.name


# 合作伙伴库基础信息
class Clsbbhzhbk_Records(ClsbbBaseModel):
    company = ForeignKey('system.Company', on_delete=CASCADE, blank=True, default=None, related_name='Clsbbhzhbk_Records')
    describe = CharField(max_length=1024, verbose_name='简介', null=True, blank=True, help_text='简介')
    business_scope = CharField(max_length=2056, verbose_name='营业范围', null=True, blank=True, help_text='营业范围')
    business_qualification = CharField(max_length=255, verbose_name='营业资质', null=True, blank=True, help_text='营业资质')
    agreement_is_signed = BooleanField(verbose_name='是否签订合作协议', null=True, blank=True)
    framework_agreement_is_signed = BooleanField(verbose_name='是否签订采购框架协议', null=True, blank=True)
    channel_purchased_is_needs = BooleanField(verbose_name='是否需要渠道商采购', null=True, blank=True)
    contact = CharField(max_length=255, verbose_name='合作伙伴联系人', null=True, blank=True)
    contact_phone = CharField(max_length=255, verbose_name='合作伙伴联系人电话', null=True, blank=True)
    maintainer = CharField(max_length=255, verbose_name='合作伙伴维护人', null=True, blank=True)
    maintainer_phone = CharField(max_length=255, verbose_name='合作伙伴维护人联系电话', null=True, blank=True)
    Introduction_method = CharField(max_length=255, verbose_name='引入方式', null=True, blank=True, help_text='引入方式')
    attachments_qualification = ForeignKey(Clsbb_Common_Pdfs, on_delete=SET_NULL, null=True, blank=True, default=None,
                                           related_name='Clsbbhzhbk_Records_attachments_qualification')  # 合作伙伴资质附件
    downloads_log = ManyToManyField(Hzhbk_Downloads_log, null=True, blank=True,
                                    related_name='Clsbbhzhbk_Records_downloads_records')  # 下载记录
    views_log = ManyToManyField(Hzhbk_Views_log, null=True, blank=True,
                                related_name='Clsbbhzhbk_Records_views_records')  # 浏览记录
    check_records = ManyToManyField(ClsbbhzhbkCheck, blank=True, null=True, related_name='Clsbbhzhbk_Records',
                                    verbose_name='审核记录')  # 审核记录
    filled_by = ForeignKey('system.User', on_delete=SET_NULL, null=True, blank=True, default=None,
                           related_name='Clsbbhzhbk_Records_filled_by')  # 支填报人
    next_checker = ForeignKey('system.User', on_delete=SET_NULL, null=True, blank=True, default=None,
                              related_name='Clsbbhzhbk_Records_next_checker')  # 下一步审核或操作的人

    def __str__(self):
        return self.name


# 公司资质库基础信息
class Clsbbgszzk_Records(ClsbbBaseModel):
    company = ForeignKey('system.Company', on_delete=CASCADE, blank=True, default=None, related_name='Clsbbgszzk_Records')
    issued_by = CharField(max_length=255, verbose_name='发证单位', null=True, blank=True, help_text='发证单位')
    issuing_date = DateField(verbose_name='发证时间', null=True, blank=True)
    expiration_date = DateField(verbose_name='资质到期时间', null=True, blank=True)
    renewal_date = DateField(verbose_name='换证日期', null=True, blank=True)
    qualification_status = BooleanField(verbose_name='资质状态', null=True, blank=True)
    contact = CharField(max_length=255, verbose_name='资质联系人', null=True, blank=True)
    qualification_classification = ForeignKey('system.Dict_item', on_delete=CASCADE, verbose_name='资质分类', blank=True, default=None,
                          related_name='Clsbbtbk_Records_dict_item_qualification_classification')
    qualification_grade = ForeignKey('system.Dict_item', on_delete=CASCADE, verbose_name='资质等级', blank=True, default=None,
                          related_name='Clsbbtbk_Records_dict_item_qualification_grade')
    contact_phone = CharField(max_length=255, verbose_name='资质联系人电话', null=True, blank=True)
    maintainer = CharField(max_length=255, verbose_name='资质维护人', null=True, blank=True)
    maintainer_phone = CharField(max_length=255, verbose_name='资质维护人联系电话', null=True, blank=True)
    attachments_company_qualification = ForeignKey(Clsbb_Common_Pdfs, on_delete=SET_NULL, null=True, blank=True, default=None,
                                           related_name='Clsbbgszzk_Records_attachments_company_qualification')  # 公司资质附件
    downloads_log = ManyToManyField(Gszzk_Downloads_log, null=True, blank=True,
                                    related_name='Clsbbgszzk_Records_downloads_records')  # 下载记录
    views_log = ManyToManyField(Gszzk_Views_log, null=True, blank=True,
                                related_name='Clsbbgszzk_Records_views_records')  # 浏览记录
    check_records = ManyToManyField(ClsbbgszzkCheck, blank=True, null=True, related_name='Clsbbgszzk_Records',
                                    verbose_name='审核记录')  # 审核记录
    filled_by = ForeignKey('system.User', on_delete=SET_NULL, null=True, blank=True, default=None,
                           related_name='Clsbbgszzk_Records_filled_by')  # 支填报人
    next_checker = ForeignKey('system.User', on_delete=SET_NULL, null=True, blank=True, default=None,
                              related_name='Clsbbgszzk_Records_next_checker')  # 下一步审核或操作的人

    def __str__(self):
        return self.name


# 人员资质库基础信息
class Clsbbryzzk_Records(ClsbbBaseModel):
    company = ForeignKey('system.Company', on_delete=CASCADE, blank=True, default=None,
                         related_name='Clsbbryzzk_Records')
    full_name = CharField(max_length=255, verbose_name='姓名', null=True, blank=True, help_text='姓名')
    professional_qualification_level = ForeignKey('system.Dict_item', on_delete=CASCADE, verbose_name='职业资格等级', blank=True,
                                     default=None,
                                     related_name='Clsbbtbk_Records_dict_item_professional_qualification_level')
    certification_discipline = CharField(max_length=255, verbose_name='认证专业', null=True, blank=True, help_text='认证专业')
    certificate_number = CharField(max_length=255, verbose_name='证书编号', null=True, blank=True, help_text='证书编号')
    issued_by = CharField(max_length=255, verbose_name='发证单位', null=True, blank=True, help_text='发证单位')
    issuing_date = DateField(verbose_name='发证日期', null=True, blank=True)
    expiration_date = DateField(verbose_name='到期日期', null=True, blank=True)
    renewal_date = DateField(verbose_name='换证日期', null=True, blank=True)
    qualification_status = BooleanField(verbose_name='资质状态', null=True, blank=True)

    maintainer = CharField(max_length=255, verbose_name='资质维护人', null=True, blank=True)
    maintainer_phone = CharField(max_length=255, verbose_name='资质维护人联系电话', null=True, blank=True)
    attachments_personnel_qualification = ForeignKey(Clsbb_Common_Pdfs, on_delete=SET_NULL, null=True, blank=True,
                                                   default=None,
                                                   related_name='Clsbbryzzk_Records_attachments_personnel_qualification')  # 人员资质附件
    downloads_log = ManyToManyField(Ryzzk_Downloads_log, null=True, blank=True,
                                    related_name='Clsbbryzzk_Records_downloads_records')  # 下载记录
    views_log = ManyToManyField(Ryzzk_Views_log, null=True, blank=True,
                                related_name='Clsbbryzzk_Records_views_records')  # 浏览记录
    check_records = ManyToManyField(ClsbbryzzkCheck, blank=True, null=True, related_name='Clsbbryzzk_Records',
                                    verbose_name='审核记录')  # 审核记录
    filled_by = ForeignKey('system.User', on_delete=SET_NULL, null=True, blank=True, default=None,
                           related_name='Clsbbryzzk_Records_filled_by')  # 支填报人
    next_checker = ForeignKey('system.User', on_delete=SET_NULL, null=True, blank=True, default=None,
                              related_name='Clsbbryzzk_Records_next_checker')  # 下一步审核或操作的人

    def __str__(self):
        return self.name
